﻿using Common.Communal;
using ERP.Domain.Products;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Product.API.Read.Applications.Commands.Bom;

namespace Product.API.Read.Controllers
{
    /// <summary>
    /// BOM API-读
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class BomController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="mediator">中介者</param>
        public BomController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 产品全量查询
        /// </summary>
        /// <returns>返回列表</returns>
        [HttpGet("ProductAll")]
        public Task<ApiResult<List<ERP.Domain.Products.Product>>> ProductAll()
        {
            ProductAllQueryCommand command = new ProductAllQueryCommand();
            return mediator.Send(command);
        }

        /// <summary>
        /// 物料全量查询
        /// </summary>
        /// <returns>返回列表</returns>
        [HttpGet("MaterialAll")]
        public Task<ApiResult<List<ERP.Domain.Products.Material>>> MaterialAll()
        {
            MaterialAllQueryCommand command = new MaterialAllQueryCommand();
            return mediator.Send(command);
        }

        /// <summary>
        /// 按BomNumber查询物料结构
        /// </summary>
        /// <param name="BomNumber">BOM编号</param>
        /// <returns>返回列表</returns>
        [HttpGet("GetMaterialStructureByBomNumber")]
        public Task<ApiResult<List<ERP.Domain.Products.MaterialStructure>>> GetMaterialStructureByBomNumber(Guid BomNumber)
        {
            GetMaterialStructureByBomNumberCommand command = new GetMaterialStructureByBomNumberCommand();
            command.BomNumber = BomNumber;
            return mediator.Send(command);
        }

        /// <summary>
        /// 按BomNumber查询BOM信息
        /// </summary>
        /// <param name="BomNumber">BOM编号</param>
        /// <returns>返回BOM信息</returns>
        [HttpGet("GetBomInfoByBomNumber")]
        public Task<ApiResult<ERP.Domain.Products.BomInfo>> GetBomInfoByBomNumber(Guid BomNumber)
        {
            GetBomInfoByBomNumberCommand command = new GetBomInfoByBomNumberCommand();
            command.BomNumber = BomNumber;
            return mediator.Send(command);
        }

        /// <summary>
        /// 按BomNumber查询产品用料
        /// </summary>
        /// <param name="BomNumber">BOM编号</param>
        /// <returns>返回列表</returns>
        [HttpGet("GetProductMaterialByBomNumber")]
        public Task<ApiResult<List<ERP.Domain.Products.ProductMaterial>>> GetProductMaterialByBomNumber(Guid BomNumber)
        {
            GetProductMaterialByBomNumberCommand command = new GetProductMaterialByBomNumberCommand();
            command.BomNumber = BomNumber;
            return mediator.Send(command);
        }

        /// <summary>
        /// 按产品编号 + 工序序号查询产品用料
        /// </summary>
        /// <param name="ProductNumber">产品编号</param>
        /// <param name="SerialNumber">工序序号</param>
        /// <returns>返回列表</returns>
        [HttpGet("GetProductMaterialByProductNumberAndSerial")]
        public Task<ApiResult<List<ERP.Domain.Products.ProductMaterial>>> GetProductMaterialByProductNumberAndSerial(Guid ProductNumber, string SerialNumber)
        {
            GetProductMaterialByProductNumberAndSerialCommand command = new GetProductMaterialByProductNumberAndSerialCommand();
            command.ProductNumber = ProductNumber;
            command.SerialNumber = SerialNumber;
            return mediator.Send(command);
        }

        /// <summary>
        /// Bom显示
        /// </summary>
        /// <param name="command">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet("BomShow")]
        public Task<ApiResult<ApiPaging<BomInfo>>> BomShow([FromQuery] BomShowCommand command)
        {
            return mediator.Send(command);
        }
    }
}
